package com.lineage.data.item_etcitem;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.data.item_etcitem.brave.StatusBraveCake;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.utils.L1SpawnUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SpawnNpcTime extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(StatusBraveCake.class);
  
  private int NeedItem = 0;
  
  private int NeedItemCount = 0;
  
  private int SetNpcId = 0;
  
  private int NpcExistTimer = 0;
  
  public static ItemExecutor get() {
    return new SpawnNpcTime();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (this.NeedItem > 0) {
      pc.getInventory().consumeItem(this.NeedItem, this.NeedItemCount);
      L1SpawnUtil.spawn(pc, this.SetNpcId, 0, this.NpcExistTimer);
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this.NeedItem = Integer.parseInt(set[1]);
      if (this.NeedItem <= 0)
        _log.error("SpawnNpcTime 设置错误：需要设定道具，请设定道具编号"); 
      this.NeedItemCount = Integer.parseInt(set[2]);
      if (this.NeedItemCount <= 0)
        _log.error("SpawnNpcTime 设置错误：需要设置道具数量，请设定道具数量"); 
      this.SetNpcId = Integer.parseInt(set[3]);
      if (this.SetNpcId <= 0)
        _log.error("SpawnNpcTime 设置错误：需要设至NpcID，请设定NpcID"); 
      this.NpcExistTimer = Integer.parseInt(set[4]);
      if (this.NpcExistTimer <= 0)
        _log.error("SpawnNpcTime 设置错误：需要设定时间(秒)，请设定时间"); 
    } catch (Exception exception) {}
  }
}
